Skip to content

docs: run the production server with bun scripts/serve.ts - #152

Merged
edbfi merged 1 commit into
mainfrom
docs/direct-start-command
Oct 7, 2026
Merged

edbfi merged 1 commit into
mainfrom
docs/direct-start-command

Conversation

@edbfi

@edbfi edbfi commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Summary

The README and CLAUDE.md tell people to start the production server with bun run start. With Bun 1.4.2's default system shell, bun run start and bun start deliver one terminal Ctrl+C to the server twice: the terminal signals the foreground process group, and bun run also forwards the signal to its child, as npm does. adapter-bun 1.0.0 treats the second delivery as a second signal (graceful_shutdown calls process.exit(1) when it is already shutting down), so a single Ctrl+C exits 1 at once with no SHUTDOWN_TIMEOUT drain: in-flight requests are cut and sveltekit:shutdown never runs, so the scheduler is not stopped. A group SIGTERM is doubled the same way (a repeated SIGHUP is already ignored by the front since #151). NODE_ENV=production bun scripts/serve.ts, which is what the start script runs, receives each signal once.

This PR changes the documented production command to NODE_ENV=production bun scripts/serve.ts and says why. It is docs only: the start package script, scripts/serve.ts, the tests and Playwright (which already runs bun scripts/serve.ts) are unchanged.

Changes

  • README.md, Production Startup: a code block with bun run build and NODE_ENV=production bun scripts/serve.ts, followed by one line explaining why bun run start and bun start are not used. The note that the start script runs the same command stays.
  • README.md, SHUTDOWN_TIMEOUT row: same meaning; "A second SIGTERM/SIGINT exits at once" now says it holds with NODE_ENV=production bun scripts/serve.ts (under bun run start the first Ctrl+C already does).
  • CLAUDE.md, Commands: the production command is NODE_ENV=production bun scripts/serve.ts, with the reason not to use bun run start.
  • CLAUDE.md, Deployment and origin: the SIGHUP note now says the hangup arrives twice under bun run start and once under the direct command, and that a Ctrl+C or group SIGTERM also arrives twice under bun run start, which forces exit 1 without the drain, with or without ORIGIN. The line naming scripts/serve.ts as the entry of start, Playwright and the container image is unchanged (still accurate).

.env.example (SHUTDOWN_TIMEOUT drains on SIGTERM/SIGINT) names no start command and stays as is. A search of every tracked doc, .env.example and CLAUDE.md/AGENTS.md (a symlink to CLAUDE.md) for bun run start, bun start, npm start and run start finds no other place.

Rationale

Changing how bun run launches the script (a bunfig [run] shell = "bun" or --shell=bun) was considered and not chosen: under the Bun shell, SIGTERM/SIGHUP sent to the launcher PID kill the launcher and orphan the server (oven-sh/bun#41802, an open PR, addresses that). The system-shell double forwarding is intentional npm parity in Bun (oven-sh/bun#36711). Running the front directly avoids both. This is the same change as edbfi/poyo-studio#90.

Validation

Real build of main at d82d4ff (this branch's base; the branch changes no code), Bun 1.4.2 on macOS 27.0.1, 2026-10-07. Each launch runs in its own process group on a free loopback port, with a private TMPDIR, its own copy of a seeded database and SHUTDOWN_TIMEOUT=3. After /api/health answers, one form POST /login is kept in flight (curl uploads its body slowly), then the whole group is signalled as a terminal does. "Drain" means the adapter waited for the request and sveltekit:shutdown ran (scheduler.stopped logged).

Launch ORIGIN Signal to the group Exit After Drain
bun run start set SIGINT (Ctrl+C) 1 0.02 s no (request cut, no scheduler.stopped)
bun start set SIGINT 1 0.02 s no
NODE_ENV=production bun scripts/serve.ts set SIGINT 0 3.03 s (deadline) yes (request held to the deadline, then 503; scheduler.stopped)
NODE_ENV=production bun scripts/serve.ts set SIGINT, again 1 s later 1 1.03 s stopped by the second signal, as documented
bun run start set SIGTERM 1 0.02 s no
NODE_ENV=production bun scripts/serve.ts set SIGTERM 0 3.03 s yes
bun run start unset (adapter only) SIGINT 1 0.02 s no (sveltekit:shutdown never ran)
NODE_ENV=production bun scripts/serve.ts unset (adapter only) SIGINT 0 3.02 s yes (scheduler.stopped)

In the two rows without ORIGIN the app refused the probe's POST with 403 (no front, so the origin check did not match), so those rows show only the exit and sveltekit:shutdown. No case left a listener or a socket directory. bun run start reported error: script "start" exited with code 1 in every case.

Local gates on head d153fb5 (the repository has no application CI; Pullfrog is the only workflow):

  • prek run --from-ref origin/main --to-ref HEAD: every applicable hook passed (whitespace, end of file, line endings, merge conflicts, case conflicts, large files, private keys, branch guard, gitleaks, svelte check via bun run check:types); JSON/TOML/YAML and biome check were skipped because no such file changed.
  • prek run --hook-stage commit-msg: Conventional Commit passed.
  • bun run check (Biome): exit 0, no fixes (3 warnings and 42 infos, all in source files this PR does not touch); bunx biome format .: exit 0, no fixes.
  • git diff origin/main --stat: README.md and CLAUDE.md only.

With Bun 1.4.2's default system shell, `bun run start` and `bun start`
deliver one terminal Ctrl+C to the server twice (the terminal signals the
foreground group and `bun run` forwards it as npm does), so adapter-bun
treats it as a second signal and exits 1 at once without the
SHUTDOWN_TIMEOUT drain. A group SIGTERM is doubled the same way.
`NODE_ENV=production bun scripts/serve.ts` receives each signal once.

Point README and CLAUDE.md at the direct command, say why, and keep the
SHUTDOWN_TIMEOUT and SIGHUP notes accurate. The `start` package script and
all code are unchanged.

Signed-off-by: edbfi <326875205+edbfi@users.noreply.github.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No issues found. This is a docs-only change and I have no suggestions.

Reviewed changes

I read the full diff of README.md and CLAUDE.md and checked it against package.json, scripts/serve.ts and scripts/serve.test.ts.

  • README Production Startup: Replaces bun run start with a bun run build and NODE_ENV=production bun scripts/serve.ts code block. It explains that bun run start and bun start deliver one Ctrl+C twice and skip the SHUTDOWN_TIMEOUT drain.
  • README SHUTDOWN_TIMEOUT row: Scopes "a second SIGTERM/SIGINT exits at once" to the direct command and notes that the first Ctrl+C already does under bun run start.
  • CLAUDE.md Commands: The production command is now the direct one, with the reason not to use bun run start.
  • CLAUDE.md Deployment and origin: The SIGHUP note now says the hangup arrives twice under bun run start and once under the direct command. It also says a Ctrl+C or group SIGTERM arrives twice under bun run start, which forces exit 1 without the drain.

The new text is consistent with the repo:

  • The command shown matches the start script in package.json (NODE_ENV=production bun scripts/serve.ts).
  • The double-SIGHUP description matches the comments at scripts/serve.ts:272 and scripts/serve.test.ts:887.
  • A search for bun run start and bun start found no other references to update.
  • Both docs that CLAUDE.md says to keep in step (CLAUDE.md and the README.md env table) were updated together.

I did not reproduce the Bun 1.4.2 signal-forwarding behaviour. The PR's validation table is the only evidence for it.

Pullfrog  | Fix it ➔ | View workflow run | Using claude-sonnet-5-5 | 𝕏

@edbfi
edbfi merged commit 4641374 into main Oct 7, 2026
1 check passed
@edbfi
edbfi deleted the docs/direct-start-command branch October 7, 2026 09:39
edbfi added a commit that referenced this pull request Oct 7, 2026
…153)

The SIGHUP comments in scripts/serve.ts and scripts/serve.test.ts explain the double hangup under `bun run start`. Keep that and add that the production command, `NODE_ENV=production bun scripts/serve.ts`, gets it once, as CLAUDE.md says since #152. Comment only.

Signed-off-by: edbfi <326875205+edbfi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant